<template>
  <div class="films">
    <div class="topper">
      <div class="main-title-1"
           :class="{active: selectRank === '观看榜'}"
           @click.prevent="handleRankSelect('观看榜')">
        观看榜
      </div>
      <div class="main-title-2"
           :class="{active: selectRank === '好评榜'}"
           @click.prevent="handleRankSelect('好评榜')">
        好评榜
      </div>
      <transition name="fade">
        <nav v-if="selectRank === '观看榜'">
          <a v-for="item in timeList" :key="item" :class="{ active: selectTime === item }"
             @click.prevent="handleTypeSelect(item)">
            <router-link :to="'/rank'">
              {{ item }}
            </router-link>
          </a>
          <div class="animation"></div>
        </nav>
      </transition>

    </div>
    <!--电影展示-->
    <div class="panel-content">
      <dl class="movie-list">
        <dd v-for="(item, index) in filmList" :key="index">
          <router-link :to=" '/film/info?fid=' + item.id">
            <div class="movie-item">
              <div class="movie-poster">
                <!-- 根据 item.isVip 的值动态设置 el-tag 的 type 和文本 -->
                <el-tag
                    class="poster-tag"
                    :type="item.vip ? 'warning' : 'success'"
                    size="small">
                  {{ item.vip ? 'VIP' : '免费' }}
                </el-tag>
                <img class="poster-default" alt=""
                     :src="item.cover">
              </div>
              <div class="movie-info">
                <div class="movie-title" title="">{{ item.name }}</div>
                <div class="movie-desc">
                  类型：{{ item.type }}<br>
                  上映时间：{{ item.releaseTime }}<br>
                  片长：{{ item.duration }}分钟<br>
                </div>
              </div>
              <div class="movie-view-time" v-if="selectRank === '观看榜'">
                <span class="movie-view-time-number">{{ item.hot }}</span>
                次
              </div>
              <div class="movie-view-time" v-if="selectRank === '好评榜'">
                <span class="movie-view-time-number">{{ item.star }}</span>
                /5 分
              </div>
            </div>

          </router-link>
        </dd>
      </dl>
    </div>
    <el-pagination
        background
        layout="prev, pager, next"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="totalItems"
        @current-change="handlePageChange">
    </el-pagination>
  </div>
</template>

<script>

import {GetFilmByPage, GetFilmEvaluateRankByPage} from "@/api/film";

export default {

  name: "Films",

  data() {
    return {
      selectTime: '全部',
      selectRank: '观看榜',
      timeList: ["全部", "本月", "本周",],
      filmList: [],
      currentPage: 1,
      pageSize: 10,
      totalItems: 0,
    }
  },

  mounted() {
    GetFilmByPage("全部", this.currentPage, this.pageSize).then(res => {
      console.log(res.data.total)
      this.filmList = res.data.items
      this.totalItems = res.data.total
    })
  },


  methods: {

    handleTypeSelect(item) {
      this.selectTime = item;
      this.currentPage = 1;
      this.selectRank = '观看榜';
      this.reloadFilmList('观看榜')
    },

    handleRankSelect(item) {
      this.selectRank = item;
      this.currentPage = 1;
      this.reloadFilmList(item)
    },

    handlePageChange(newPage) {
      this.currentPage = newPage;
      this.reloadFilmList(this.selectRank);
    },

    reloadFilmList(type) {
      if (type === '观看榜') {
        GetFilmByPage(this.selectTime, this.currentPage, this.pageSize).then(res => {
          this.filmList = res.data.items;
          this.totalItems = res.data.total;
        })
      } else { // 好评榜
        console.log(this.currentPage);
        GetFilmEvaluateRankByPage(this.currentPage, this.pageSize).then(res => {
          this.filmList = res.data.items;
          this.totalItems = res.data.total;
          console.log(this.totalItems);
        })
      }
    },

  },

}
</script>

<style scoped>

.films {
  padding: 20px 220px;
}

.topper {
  position: relative;
  left: 175px;
  margin-top: 20px;
  height: 85px;
}

.main-title-1 {
  position: relative;
  display: inline-block;

  font-size: 15px;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  font-weight: bolder;
  color: #FFFFFF;
  transition: all 0.5s ease-in-out;
}

.main-title-1:hover {
  color: #7b8cf6;
  transition: all 0.3s ease-in-out;
  cursor: pointer;
}

.main-title-1.active {
  font-size: 60px;
  transition: all 0.5s ease-in-out;
}

.main-title-2 {
  position: relative;
  display: inline-block;
  left: 15px;

  font-size: 15px;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  font-weight: bolder;
  color: #FFFFFF;
  transition: all 0.5s ease-in-out;
}

.main-title-2:hover {
  color: #7b8cf6;
  transition: all 0.3s ease-in-out;
  cursor: pointer;
}

.main-title-2.active {
  font-size: 60px;
  transition: all 0.5s ease-in-out;
}

::v-deep nav {

  position: absolute;
  left: 260px;
  bottom: 10px;

  width: 180px;
  height: 40px;
  padding: 0 0;
  border-radius: 8px;
  box-shadow: 0 2px 3px rgba(0, 0, 0, 0.1);
  background-color: #28243c;

  z-index: 2;

  transition: opacity 0.5s ease-in-out;
}

::v-deep .fade-enter-active,
::v-deep .fade-leave-active {
  transition: opacity 0.5s ease-in-out;
}

::v-deep .fade-enter,
::v-deep .fade-leave-to {
  opacity: 0;
}

nav a {
  position: relative;
  display: block;
  float: left;
  font-size: 15px;
  line-height: 40px;

  height: 50px;
  color: #fff;
  text-transform: uppercase;
  text-decoration: none;
  text-align: center;
  /* background-color: #00b894; */
  z-index: 10;

  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
}

nav a {
  width: 60px;
  transition: all 0.3s;
}

nav a.active a {
  font-weight: bolder;
  color: #7b8cf6;
}

nav a:hover a {
  color: #f0f0f0;
}

nav .animation {
  position: absolute;
  height: 100%;
  background-color: #7b8cf6;
  z-index: 9;
  border-radius: 8px;
  transition: all 0.3s;
}

nav a:hover ~ .animation {
  width: 60px;
}

nav a:nth-child(1):hover ~ .animation {
  left: calc(0 * 60px);
}

nav a:nth-child(2):hover ~ .animation {
  left: calc(1 * 60px);
}

nav a:nth-child(3):hover ~ .animation {
  left: calc(2 * 60px);
}

.panel-content {
  overflow: hidden;
  width: 100%;
  margin-top: 23px;
  display: flex;
  justify-content: center;
}

.movie-list {
  margin: -20px 0 20px -25px;
}

.movie-list dd {
  margin: 30px 0 0 30px;
  display: inline-block;
  vertical-align: top;
  position: relative;
  width: 750px;
  left: 175px;
}

.movie-item {
  position: relative;
  margin: -1px;
  border: none;
  background-color: #28243c;
  box-shadow: rgba(0, 0, 0, 0.25) 0px 14px 28px, rgba(0, 0, 0, 0.22) 0px 10px 10px;
  transition: all 0.4s ease-in-out;
  border-radius: 7px;
}

.movie-item:hover {
  transform: scale(1.1);
  transition: all 0.4s ease-in-out;
}

dd:nth-child(1) .movie-item {
  background-color: #7b8cf6;
}

dd:nth-child(2) .movie-item {
  background-color: #6762be;
}

dd:nth-child(3) .movie-item {
  background-color: #4c3f6a;
}

.movies-panel .film-channel:hover .movie-item-hover {
  display: block
}

.movie-poster {
  background-color: #1f1c30;
  width: 160px;
  height: 220px;
  overflow: hidden;
  position: relative;
  border-radius: 7px 0 0 7px;
}

.movie-poster a {
  display: block
}

.poster-tag {
  position: relative;
  left: -2px;
  top: -2px;
  z-index: 5;
}

.poster-movie-tag {
  z-index: 5;
}

.movie-poster img {
  width: 100%;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0
}

.movie-poster .movie-poster-img[src] {
  visibility: visible;
}

.movie-poster .movie-poster-img[data-src] {
  visibility: hidden;
}

.movie-info {
  font-size: 15px;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  color: #fff;
  position: absolute;
  margin: auto;
  top: 7px;
  left: 180px;
}

.movie-title {
  margin-left: 5px;
  margin-top: 20px;
  margin-bottom: 20px;
  width: 100%;
  transition: all 0.4s ease-in-out;
  font-weight: bolder;
  font-size: 30px;
  letter-spacing: 2px;
}

.movie-desc {
  font-size: 15px;
  line-height: 30px;
  margin-left: 10px;
}

.movie-view-time {
  font-size: 20px;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  color: #fff;

  position: absolute;
  margin: auto;
  top: 65px;
  right: 35px;
}

.movie-view-time-number {
  font-size: 60px;
  font-family: "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  font-weight: bolder;
}

::v-deep .el-pagination {
  text-align: center;
  margin-top: 30px;
}

::v-deep .el-select-dropdown__item li {
  background-color: transparent !important;
}

::v-deep .el-pagination .btn-next,
::v-deep .el-pagination .btn-prev {
  background-color: #494560 !important;
  color: #b1abca !important;
  transition: all 0.2s ease-in-out;
}

::v-deep .el-pagination button:disabled {
  color: #1f1c30 !important;
  background-color: #3b374c !important;
}

::v-deep .el-pager li {
  color: #b7b7b7 !important;
  font-family: "PingFang SC", "Microsoft YaHei", Arial, Helvetica, sans-serif, "宋体";
  background-color: #494560 !important;
  transition: all 0.2s ease-in-out;
}

::v-deep .el-pager li.hover,
::v-deep .el-pager li:hover,
::v-deep .el-pagination button:hover {
  color: #7b8cf6 !important;
  background-color: #635c86 !important;
  transition: all 0.2s ease-in-out;
}

::v-deep .el-pager li.active {
  color: #ffffff !important;
  background-color: #7b8cf6 !important;
}

</style>
